import axios from 'axios'
import {takeEvery, put} from 'redux-saga/effects'
import { API } from '../../config'
import { get_products, get_products_success } from '../actions/product'

function* handleGetProducts (action) {
    let res = yield axios.get(`${API}/products`, {
        params: action.payload
    })
    yield put(get_products_success({
        sortBy: action.payload.sortBy,
        products: res.data
    }))
}

export default function* productSaga () {
    yield takeEvery(get_products, handleGetProducts)
}
